#ifndef FENPRINCIPALE_H
#define FENPRINCIPALE_H

#include <QtGui>
#include <QtSql>
#include <QDialog>
#include <QtNetwork>
#include "utilisateur.h"
#include "enquete.h"
#include "buttonq.h"

class QSqlTableModel;

namespace Ui {
class FenPrincipale;
}

class FenPrincipale : public QMainWindow
{
    Q_OBJECT
    
public:
    explicit FenPrincipale(QWidget *parent = 0);
    ~FenPrincipale();
    void connecterBdd();
    Utilisateur* getUnUtilisateur() const;
    Enquete* getUneEnquete() const;

    void enregistrerEnquete();
    void connectionReseau();
    //void envoiInfo(const QString &info);
    
private:
    void setupUiInfo();
    void setupUiSuper();
    void setupUiQuestion();
    void setupActions();

    Ui::FenPrincipale *ui;

    QFrame *cadreNum;
    QTableView *vueListeInfo;
    QSqlQueryModel *modelListeInfoQuery;
    QPushButton *bEtatNum;

    QStandardItemModel *modelListeTM;
    QTableView *vueListeTM;

    QWidget *vueQuestions;
    QList<QGroupBox*> lgbQuestions;
    ButtonQ *nextQ;

    QAction *bCommencer;
    QAction *bPause;
    QAction *bAide;
    QAction *bInfo;
    QAction *bSuper;
    QAction *bNewInfo;
    QAction *bAnnuleQuestion;

    Enquete *uneEnquete;
    Utilisateur *unUtilisateur;

    QTcpSocket *socket; // Represente la connection au serveur
    quint16 tailleMessage;

    //QSqlDatabase connectionBdd;

private slots:
    void modePause();
    void modeInfo();
    void modeQuestion();
    void modeSuper();
    void demandeAssistance(bool valide);
    void superDoubleClicked(QModelIndex mIndex);
    void infoModif(QModelIndex mIndex);
    void infoNew();
    void annuleEnquete();

    void blackListerNum();

    void prochaineQuestion();

    void connecteReseau();
    void donneesRecues();
    void traitementMessage(QString &message);

    void envoiInfo(const QString &info);
    void deconnecte();
};

#endif // FENPRINCIPALE_H
